---
layout: "default"
description: "Swift documentation for 'withExtendedLifetime'"
root: "/v5.1"
keywords: ""
title: "withExtendedLifetime"
---

<div class="intro-declaration"><code class="language-swift">func withExtendedLifetime(_:_:)(_ x: T, _ body: () throws -> Result) rethrows -> Result</code></div><div class="discussion comment"><p>Evaluates a closure while ensuring that the given instance is not destroyed
before the closure returns.
</p>
</div><div class="intro-declaration"><code class="language-swift">func withExtendedLifetime(_:_:)(_ x: T, _ body: (T) throws -> Result) rethrows -> Result</code></div><div class="discussion comment"><p>Evaluates a closure while ensuring that the given instance is not destroyed
before the closure returns.
</p>
</div>